﻿/*
  In App.xaml:
  <Application.Resources>
      <vm:ViewModelLocatorTemplate xmlns:vm="clr-namespace:SGT.ViewModel"
                                   x:Key="Locator" />
  </Application.Resources>
  
  In the View:
  DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"
  
  OR (WPF only):
  
  xmlns:vm="clr-namespace:SGT.ViewModel"
  DataContext="{Binding Source={x:Static vm:ViewModelLocatorTemplate.ViewModelNameStatic}}"
*/

using SGT.Model;

using GalaSoft.MvvmLight;

namespace SGT.ViewModel
{
    /// <summary>
    /// This class contains static references to all the view models in the
    /// application and provides an entry point for the bindings.
    /// <para>
    /// Use the <strong>mvvmlocatorproperty</strong> snippet to add ViewModels
    /// to this locator.
    /// </para>
    /// <para>
    /// In Silverlight and WPF, place the ViewModelLocatorTemplate in the App.xaml resources:
    /// </para>
    /// <code>
    /// &lt;Application.Resources&gt;
    ///     &lt;vm:ViewModelLocatorTemplate xmlns:vm="clr-namespace:SGT.ViewModel"
    ///                                  x:Key="Locator" /&gt;
    /// &lt;/Application.Resources&gt;
    /// </code>
    /// <para>
    /// Then use:
    /// </para>
    /// <code>
    /// DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"
    /// </code>
    /// <para>
    /// You can also use Blend to do all this with the tool's support.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// <para>
    /// In <strong>*WPF only*</strong> (and if databinding in Blend is not relevant), you can delete
    /// the Main property and bind to the ViewModelNameStatic property instead:
    /// </para>
    /// <code>
    /// xmlns:vm="clr-namespace:SGT.ViewModel"
    /// DataContext="{Binding Source={x:Static vm:ViewModelLocatorTemplate.ViewModelNameStatic}}"
    /// </code>
    /// </summary>
    public class ViewModelLocator
    {
        private static MainViewModel _main;
        private static ABMProvedoresViewModel _ABMProvedores;
   
        private static ABMDepositosViewModel _ABMDepositos;
        private static ABMMercaderiasViewModel _ABMMercaderias;
        private static RemitoViewModel _Remitos;
        private static PortadaViewModel _Portada;



       

        /// <summary>
        /// Initializes a new instance of the ViewModelLocator class.
        /// </summary>
        public ViewModelLocator()
        {
            ////if (ViewModelBase.IsInDesignModeStatic)
            ////{
            ////    // Create design time view models
            ////}
            ////else
            ////{
            ////    // Create run time view models
            ////}
          


            CreateMain();
            CreateABMProvedores();
            CreateABMDepositos();
        }

        /// <summary>
        /// Gets the Main property.
        /// </summary>
        public static MainViewModel MainStatic
        {
            get
            {
                if (_main == null)
                {
                    CreateMain();
                }

                return _main;
            }
        }

         public static ABMProvedoresViewModel ABMProvedoresStatic
        {
            get
            {
                if (_ABMProvedores == null)
                {
                    CreateABMProvedores();
                }

                return _ABMProvedores;
            }
        }

         public static ABMDepositosViewModel ABMDepositosStatic
         {
             get
             {
                 if (_ABMDepositos == null)
                 {
                     CreateABMDepositos();
                 }

                 return _ABMDepositos;
             }
         }

         public static ABMMercaderiasViewModel ABMMercaderiasStatic
         {
             get
             {
                 if (_ABMMercaderias == null)
                 {
                     CreateABMMercaderias();
                 }

                 return _ABMMercaderias;
             }
         }
         public static RemitoViewModel RemitosStatic
         {
             get
             {
                 if (_Remitos == null)
                 {
                     CreateRemitos();
                 }

                 return _Remitos;
             }
         }

         public static PortadaViewModel PortadaStatic
         {
             get
             {
                 if (_Portada == null)
                 {
                     CreatePortada();
                 }

                 return _Portada;
             }
         }




        /// <summary>
        /// Gets the Main property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public MainViewModel Main
        {
            get
            {
                return MainStatic;
            }
        }

         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public ABMProvedoresViewModel ABMProvedores
        {
            get
            {
                return ABMProvedoresStatic;
            }
        }

         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
         public ABMDepositosViewModel ABMDepositos
         {
             get
             {
                 return ABMDepositosStatic;
             }
         }
         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
         public ABMMercaderiasViewModel ABMMercaderias
         {
             get
             {
                 return ABMMercaderiasStatic;
             }
         }

         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
             "CA1822:MarkMembersAsStatic",
             Justification = "This non-static member is needed for data binding purposes.")]
         public RemitoViewModel Remitos
         {
             get
             {
                 return RemitosStatic;
             }
         }

         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
             "CA1822:MarkMembersAsStatic",
             Justification = "This non-static member is needed for data binding purposes.")]
         public PortadaViewModel Portada
         {
             get
             {
                 return PortadaStatic;
             }
         }




        /// <summary>
        /// Provides a deterministic way to delete the Main property.
        /// </summary>
        public static void ClearMain()
        {
            _main.Cleanup();
            _main = null;
        }

        public static void ClearABMProvedores()
        {
            _ABMProvedores.Cleanup();
            _ABMProvedores = null;
        }

        public static void ClearABMMercaderias()
        {
            _ABMMercaderias.Cleanup();
            _ABMMercaderias = null;
        }

        public static void ClearRemitos()
        {
            _Remitos.Cleanup();
            _Remitos = null;
        }
        public static void ClearPortada()
        {
            _Portada.Cleanup();
            _Portada = null;
        }

        /// <summary>
        /// Provides a deterministic way to create the Main property.
        /// </summary>
        public static void CreateMain()
        {
            if (_main == null)
            {
                _main = new MainViewModel();
            }
        }

        public static void CreateABMProvedores()
        {
            if (_ABMProvedores == null)
            {
                _ABMProvedores = new ABMProvedoresViewModel();
            }
        }

        public static void CreateABMDepositos()
        {
            if (_ABMDepositos == null)
            {
                _ABMDepositos = new ABMDepositosViewModel();
            }
        }
        public static void CreateABMMercaderias()
        {
            if (_ABMMercaderias == null)
            {
                _ABMMercaderias = new ABMMercaderiasViewModel();
            }
        }

        public static void CreateRemitos()
        {
            if (_Remitos == null)
            {
                _Remitos = new RemitoViewModel();
            }
        }

        public static void CreatePortada()
        {
            if (_Portada == null)
            {
                _Portada = new PortadaViewModel();
            }
        }

        /// <summary>
        /// Cleans up all the resources.
        /// </summary>
        public static void Cleanup()
        {
            ClearMain();
        }
    }
}